<!DOCTYPE html>
<html lang="zh_CN" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<base th:href="@{/}">
	<meta charset="utf-8">
	<title></title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="stylesheet" href="static/layui/css/layui.css" media="all" />
	<link rel="stylesheet" type="text/css" href="static/jquery-easyui/themes/default/easyui.css">
	<link rel="stylesheet" type="text/css" href="static/jquery-easyui/themes/icon.css">
	<script type="text/javascript" src="static/jquery-easyui/jquery.min.js"></script>
	<script type="text/javascript" src="static/layui/layui.js"></script>
	<script type="text/javascript" src="static/jquery-easyui/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="static/jquery-easyui/locale/easyui-lang-zh_CN.js"></script>
	<style>
		.layui-form-label{
			width: 120px;
		}
	</style>
</head>
<body class="layui-fluid">
<div class="layui-row">
	<div class="layui-row" style="margin-top: 5px;">
		<div class="layui-col-md12">
			<div class="layui-collapse" lay-filter="search">
				<div class="layui-colla-item">
					<div class="layui-colla-content layui-show">
						<form class="layui-form">
							<div class="layui-form-item">
								<div class="layui-inline">
									<label class="layui-form-label">数据表</label>
									<div class="layui-input-inline">
										<select id="constantId" lay-filter="constantId" lay-search>
											<option value=""></option>
											<option th:each="e:${constantList}" th:value="${e.id}" th:text="${e.name}"></option>
										</select>
									</div>
								</div>
								<div class="layui-inline">
									<label class="layui-form-label">联查字段</label>
									<div class="layui-input-inline">
										<select id="criteriaField" lay-search>
											<option value="">请选择</option>
										</select>
									</div>
								</div>
							</div>
						</form>
					</div>
				</div>
			</div>
		</div>
	</div>
	<h2 class="layui-colla-title" style="margin-top: 20px;">表体字段</h2>
	<div class="layui-col-md12">
		<table id="table" class="layui-table" lay-filter="table"></table>
	</div>
</div>
<script type="text/javascript" th:inline="javascript">
	var table,layer;
	var associatedFiled = [[${associatedFiled}]];
	var queryConstantId = [[${queryConstantId}]];
	var id = [[${id}]];
	console.log(id);
	layui.use(['form','layer','jquery','table'],function(){
		var form = layui.form,
			laypage = layui.laypage,
			$ = layui.jquery;
			table=layui.table;
			layer = layui.layer;

		if(queryConstantId != null){
			//获取页面加载时，默认的选中值
			var select = 'dd[lay-value="' + queryConstantId + '"]';
			//模拟鼠标选中下拉项事件
			setTimeout(function () {
				$('#constantId').siblings("div.layui-form-select").find('dl').find(select).click();
				form.render();
			},200)
		}

		form.on('select(constantId)', function(data){
			var tableIns = table.render({
				elem:'#table'
				,title:'用户列表'
				,url:'/manage/common_data_dictionary_and_set/field_list/'+data.value+'/'+id
				,method:'post'
				,page: false //开启分页
				,loading: true
				,cols: [[ //表头
					{type:'checkbox'}
					,{field:'tableKey',title:'主键'}
					,{field:'tableField',title:'字段'}
					,{field:'fieldExplain',title:'字段描述'}
					,{field:'fieldType',title:'字段类型'}
					,{field:'numericScal',title:'小数位数'}
					,{field:'entityField',title:'对象属性'}
				]]
				,text: {
					none: '暂无相关数据' //默认：无数据。注：该属性为 layui 2.2.5 开始新增
				}
				,done: function (res, curr, count){
					var html = '';
					for(var i in res.data){
						if(associatedFiled != null && associatedFiled == res.data[i].tableField){
							html = html+'<option value="'+res.data[i].tableField+'" selected>'+(res.data[i].fieldExplain == ''?res.data[i].tableField:res.data[i].fieldExplain)+'</option>';
						}else{
							html = html+'<option value="'+res.data[i].tableField+'">'+(res.data[i].fieldExplain == ''?res.data[i].tableField:res.data[i].fieldExplain)+'</option>';
						}
					}
					$("#criteriaField").html(html);
					form.render();
				}
			});
		});
	})

	function backData(){
		var constantId = $("#constantId").val();
		if(constantId == ''){
			top.layer.msg("请选择数据表",{icon:2});
			return;
		}
		var criteriaField = $("#criteriaField").val();
		if(criteriaField == ''){
			top.layer.msg("请选择联查字段",{icon:2});
			return;
		}
		var obj = new Object();
		obj.constantId = constantId;
		obj.associatedFiled = criteriaField;
		var checkStatus = table.checkStatus('table').data;
		var fields =new Array();
		for(var i in checkStatus){
			fields.push(checkStatus[i].tableField);
		}
		if(fields.length < 1){
			top.layer.msg("请勾选要联查的字段",{icon:2});
			return;
		}
		obj.fields = fields;
		return obj;
	}
</script>
</body>
</html>